Adding some more judges, here and there.
[and.git] / Codeforces / Codeforces Beta Round #90 / B / b.cpp
blob031bfd64531e5c823e4f08d3911561f15824d4f9
1 using namespace std;
2 #include <algorithm>
3 #include <iostream>
4 #include <iterator>
5 #include <numeric>
6 #include <sstream>
7 #include <fstream>
8 #include <cassert>
9 #include <climits>
10 #include <cstdlib>
11 #include <cstring>
12 #include <string>
13 #include <cstdio>
14 #include <vector>
15 #include <cmath>
16 #include <queue>
17 #include <deque>
18 #include <stack>
19 #include <list>
20 #include <map>
21 #include <set>
23 #define foreach(x, v) for (typeof (v).begin() x=(v).begin(); x !=(v).end(); ++x)
24 #define For(i, a, b) for (int i=(a); i<(b); ++i)
25 #define D(x) cout << #x " is " << x << endl
27 int prof[105];
28 bool used[105];
29 set< vector<int> > seen;
31 int main(){
32 int n, k;
33 while (cin >> n >> k) {
34 memset(used, 0, sizeof used);
35 seen.clear();
36 For(i, 0, n) cin >> prof[i];
38 int ans_min = 1<<28, ans_max = -(1<<28);
40 int q; cin >> q;
41 while (q--) {
42 int sum = 0;
43 vector<int> card;
44 for (int i = 0; i < (n/k); ++i) {
45 int x; cin >> x; x--;
46 used[x] = true;
47 sum += prof[x];
48 card.push_back(x);
50 sort(card.begin(), card.end());
51 seen.insert(card);
52 ans_min = min(sum, ans_min);
53 ans_max = max(sum, ans_max);
56 vector<int> unused;
57 For(i, 0, n) if (!used[i]) unused.push_back(prof[i]);
58 sort(unused.begin(), unused.end());
59 if (unused.size() >= (n/k) and seen.size() < k) {
60 assert(unused.size() >= (n/k));
61 int small = 0, big = 0;
62 for (int i = 0; i < (n/k); ++i) small += unused[i];
63 for (int i = 0; i < (n/k); ++i) big += unused[unused.size() - 1 - i];
64 ans_min = min(small, ans_min);
65 ans_min = min(big, ans_min);
67 ans_max = max(small, ans_max);
68 ans_max = max(big, ans_max);
70 int f = n / k;
71 printf("%.12lf %.12lf\n", 1.0 * ans_min / f, 1.0 * ans_max / f);
73 return 0;